﻿using System;
using System.Data;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using FineUI;
using Maticsoft.BLL;
using Maticsoft.Model;

namespace FineUI.Examples
{
    public partial class admin_manage_teacher : System.Web.UI.Page
    {
        protected DataSet LoadTeacherInform()
        {
            Maticsoft.BLL.Teacher currentTeacher = new Maticsoft.BLL.Teacher();
            DataSet DSTeacher = currentTeacher.GetAllList();


            DataView view1 = DSTeacher.Tables[0].DefaultView;
            GridTeacher.DataSource = view1;
            GridTeacher.DataBind();
            return DSTeacher;

        }
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Session["UserName"] == null)
            {
                Response.Redirect("~/login.aspx");
            }
            LoadTeacherInform();
        }


        protected void GridTeacher_PageIndexChange(object sender, GridPageEventArgs e)
        {
            GridTeacher.PageIndex = e.NewPageIndex;
            LoadTeacherInform();
        }

        protected void btnUpdateTeaInform_Click(object sender, EventArgs e)
        {
            //int index = Convert.ToInt32(Session["current_Teacher_Grid_Index"]);
            if (tbxUserName.Text == "")
            {
                Alert.Show("请选中一行", MessageBoxIcon.Information);
                return;
            }


            string currentT_Id = tbxUserName.Text.ToString();
            string currentT_Password = tbxPassword.Text.ToString();
            string currentT_Name = tbxName.Text.ToString();
            string currentT_Sex = tbxSex.Text.ToString();
            string currentT_Department = tbxDepartment.Text.ToString();
            string currentT_Duty = tbxDuty.Text.ToString();
            string currentT_Contact = tbxConnect.Text.ToString();
            string currentT_Email = tbxEmail.Text.ToString();

            Maticsoft.BLL.Teacher TC = new Maticsoft.BLL.Teacher();
            Maticsoft.Model.Teacher TCInform = TC.GetModel(currentT_Id);
            TCInform.T_Password = currentT_Password;
            TCInform.T_Name = currentT_Name;
            TCInform.T_Sex = currentT_Sex;
            TCInform.T_Department = currentT_Department;
            TCInform.T_Duty = currentT_Duty;
            TCInform.T_Contact = currentT_Contact;
            TCInform.T_Email = currentT_Email;

            if (!TC.Update(TCInform))
            {

                Alert.ShowInTop("修改信息失败！", MessageBoxIcon.Information);
            
            }
            LoadTeacherInform();

        }

        protected void GridTeacher_RowClick(object sender, GridRowClickEventArgs e)
        {

            int index = e.RowIndex;
           // Session["current_Teacher_Grid_Index"] = index;
            DataSet currentDataSet = LoadTeacherInform();
            string currentT_Id = currentDataSet.Tables[0].Rows[index]["T_Id"].ToString();
            string currentT_Password = currentDataSet.Tables[0].Rows[index]["T_Password"].ToString();
            string currentT_Name = currentDataSet.Tables[0].Rows[index]["T_Name"].ToString();
            string currentT_Sex = currentDataSet.Tables[0].Rows[index]["T_Sex"].ToString();
            string currentT_Department = currentDataSet.Tables[0].Rows[index]["T_Department"].ToString();
            string currentT_Duty = currentDataSet.Tables[0].Rows[index]["T_Duty"].ToString();
            string currentT_Contact = currentDataSet.Tables[0].Rows[index]["T_Contact"].ToString();
            string currentT_Email = currentDataSet.Tables[0].Rows[index]["T_Email"].ToString();

            tbxUserName.Text = currentT_Id;
            tbxPassword.Text = currentT_Password;
            tbxName.Text = currentT_Name;
            tbxSex.Text = currentT_Sex;
            tbxDuty.Text = currentT_Duty;
            tbxDepartment.Text = currentT_Department;
            tbxConnect.Text = currentT_Contact;
            tbxEmail.Text = currentT_Email;


        }
    }
}